
package tasks;

import java.util.ArrayList;

import core.Executor;
import core.Peer;
import core.Torrent;
import core.TorrentManager;


public class ContactPeer implements Runnable {

	private Torrent torrent;

	public ContactPeer(Torrent torrent ){

		this.torrent = torrent;

	}

	@Override
	public void run() {

		int i = 0;
		int taille = 0;
		ArrayList<Peer> liste;

		while(taille == 0) {
			liste = TorrentManager.getInstance().getPeersByTorrent(torrent.getHashInfo());
			i = 0;
			taille = liste.size();

			while(i<taille){
				Executor.getThreadPool().execute(new RequestPeer(torrent,liste.get(i)));
				liste = TorrentManager.getInstance().getPeersByTorrent(torrent.getHashInfo());

				i++;
				taille = liste.size();
			}
			
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
